package cn.com.guage.dtm.design.pattern.factory.staticstate;
// 支付接口
interface Payment {
    void pay(double amount);
}

// 支付宝支付实现类
class Alipay implements Payment {
    @Override
    public void pay(double amount) {
        System.out.println("使用支付宝支付了 " + amount + " 元");
    }
}

// 微信支付实现类
class WechatPay implements Payment {
    @Override
    public void pay(double amount) {
        System.out.println("使用微信支付了 " + amount + " 元");
    }
}

// 银行卡支付实现类
class BankCardPay implements Payment {
    @Override
    public void pay(double amount) {
        System.out.println("使用银行卡支付了 " + amount + " 元");
    }
}

// 支付工厂类
class PaymentFactory {
    public static Payment createPayment(String paymentType) {
        switch (paymentType.toLowerCase()) {
            case "alipay":
                return new Alipay();
            case "wechatpay":
                return new WechatPay();
            case "bankcardpay":
                return new BankCardPay();
            default:
                throw new IllegalArgumentException("不支持的支付类型: " + paymentType);
        }
    }
}

// 主类
public class 静态工厂模式_支付实现 {
    public static void main(String[] args) {
        // 创建支付宝支付对象并支付
        Payment alipay = PaymentFactory.createPayment("alipay");
        alipay.pay(100.0);

        // 创建微信支付对象并支付
        Payment wechatPay = PaymentFactory.createPayment("wechatpay");
        wechatPay.pay(200.0);

        // 创建银行卡支付对象并支付
        Payment bankCardPay = PaymentFactory.createPayment("bankcardpay");
        bankCardPay.pay(300.0);
    }
}
